package com.fuxin.hanfu.controller;

import com.fuxin.hanfu.domain.Item;
import com.fuxin.hanfu.domain.Knowledge;
import com.fuxin.hanfu.service.KnowledgeService;
import com.fuxin.hanfu.uitls.MyResponse;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/knowledge")
public class KnowledgeController {
    @Resource
    private KnowledgeService knowledgeService;
//    查询
    @GetMapping("/find")
    public List<Knowledge> findList(Knowledge knowledge){
        return knowledgeService.findList(knowledge);
    }

    /*根据id查询*/
    @GetMapping("/find/{id}")
    public MyResponse findById(@PathVariable Integer id) {
        return MyResponse.toJson(true, knowledgeService.findById(id));}
//    新增
    @PostMapping("/add")
    public MyResponse insert(@RequestBody Knowledge knowledge) {
    return  MyResponse.toJson(true, knowledgeService.insert(knowledge));
    }
    //修改
    @PutMapping("/update")
    public MyResponse update(@RequestBody Knowledge knowledge) {
        return MyResponse.toJson(true, knowledgeService.update(knowledge));
    }
    //    删除
    @DeleteMapping("/delete/{id}")
    public Integer delete(@PathVariable Integer id) {
        return  knowledgeService.delete(id);
    }

    }
